import os
import shutil
import time


def list_files(directory):
    my_list = []
    for root, dirs, files in os.walk(directory):
        for file in files:
            my_list.append(os.path.join(root, file))
    return my_list


if __name__ == '__main__':
    """
    把D:\\1\\的mp4文件移动到D:\\2\\,如果文件已存在则不移动
    """
    print('开始')
    timestamp = int(time.time())
    original_file_path = 'D:\\1\\'
    final_file_path = 'D:\\2\\'
    my_list = list_files(original_file_path)
    for element in my_list:
        _, file_extension = os.path.splitext(element)
        if file_extension.lower() == '.mp4' or file_extension.lower() == '.flv' or file_extension.lower() == '.mov' or file_extension.lower() == '.avi' or file_extension.lower() == '.wmv' or file_extension.lower() == '.ts'or file_extension.lower() == '.mpg'or file_extension.lower() == '.m4v'or file_extension.lower() == '.mkv':
            file_name = os.path.split(element)[-1]
            file_path = final_file_path + file_name
            if os.path.exists(file_path):
                print(element)
            else:
                shutil.move(element, file_path)

    aaa = set()
    for element in my_list:
        _, file_extension = os.path.splitext(element)
        aaa.add(file_extension)
    print(aaa)

    endTime = int(time.time())
    print(str(endTime - timestamp))
    print('结束')
